using System;
using System.IO;

namespace kerberosLibs
{
	/// <summary>
	/// Start a VNC task to a remote machine. Currently only takes port number and username. Perhaps
	/// we can eventually do the password if I can figure out how to convince vnc.
	/// </summary>
	public class TaskVNC : LoggingConnectionTask
	{
		public TaskVNC()
		{
		}

		/// <summary>
		/// How many steps are involved?
		/// </summary>
		public override int NumberOfSteps
		{
			get
			{
				return 3;
			}
		}

		int _vncPort = 0;
		string _remoteMachine;

		/// <summary>
		/// Get/Set Port number on remote machine to point vnc viewer at!
		/// </summary>
		public int VNCPort 
		{
			get {return _vncPort;}
			set {_vncPort = value;}
		}

		/// <summary>
		/// Get/Set what internet addresss should we be connecting to?
		/// </summary>
		public string RemoteMachine
		{
			get {return _remoteMachine;}
			set {_remoteMachine = value;}
		}

		/// <summary>
		/// Run the VNC application!
		/// </summary>
		public override void Start()
		{
			OnUIStatusUpdate (0, "Starting VNC Viewer");

			string vnc_exe = kerberosLibs.kerberosProductAccess.VNCViewerPath;
			System.Text.StringBuilder bld = new System.Text.StringBuilder ();
			bld.AppendFormat ("{1}:{0}", _vncPort, _remoteMachine);

			InitProcess (new FileInfo(vnc_exe), bld.ToString());
			StartProcess();

			///
			/// Now, wait until the vnc guy us up and running...
			///

			OnUIStatusUpdate (1, "Waiting for VNC to start");
			_proc.WaitTillIdle();
			OnUIStatusUpdate (2, "VNC Viewer up and running!");
		}

	}
}
